package com.atguigu.admin.config;

import com.atguigu.admin.interceptor.LoginInterceptor;
import com.atguigu.admin.interceptor.RedisUrlCountInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * ClassName: AdminWebConfig
 * Package: com.atguigu.admin.config
 * Description:
 *
 * @Author Root
 * @Create 2023/4/4 10:27
 * @Version 1.0
 */
@Configuration
//@EnableWebMvc
public class AdminWebConfig implements WebMvcConfigurer {
    @Autowired
    private RedisUrlCountInterceptor redisUrlCountInterceptor;

    /**
     * 定义静态资源
     * @param registry
     */
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        //访问  /aa/**/ 所有请求都去 classpath:/static/下面匹配
//        registry.addResourceHandler("/aa/**")
//                .addResourceLocations("classpath:/static/");
//    }



    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")//所有请求都被拦截包括静态资源
                .excludePathPatterns("/","/login","/css/**","/fonts/**","/images/**","/js/**","/aa/**");//放行

        registry.addInterceptor(redisUrlCountInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/","/login","/css/**","/fonts/**","/images/**","/js/**","/aa/**");

    }





}
